package io.xccit.race.service.impl;

import java.util.List;
import io.xccit.common.utils.DateUtils;
import io.xccit.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import io.xccit.race.mapper.RaceCompetitionAppealMapper;
import io.xccit.race.domain.RaceCompetitionAppeal;
import io.xccit.race.service.IRaceCompetitionAppealService;

/**
 * 竞赛申诉管理Service业务层处理
 * 
 * @author ywx
 * @date 2025-10-13
 */
@Service
public class RaceCompetitionAppealServiceImpl implements IRaceCompetitionAppealService {
    @Autowired
    private RaceCompetitionAppealMapper raceCompetitionAppealMapper;

    /**
     * 查询竞赛申诉管理
     * 
     * @param id 竞赛申诉管理主键
     * @return 竞赛申诉管理
     */
    @Override
    public RaceCompetitionAppeal selectRaceCompetitionAppealById(Long id) {
        return raceCompetitionAppealMapper.selectRaceCompetitionAppealById(id);
    }

    /**
     * 查询竞赛申诉管理列表
     * 
     * @param raceCompetitionAppeal 竞赛申诉管理
     * @return 竞赛申诉管理
     */
    @Override
    public List<RaceCompetitionAppeal> selectRaceCompetitionAppealList(RaceCompetitionAppeal raceCompetitionAppeal) {
        return raceCompetitionAppealMapper.selectRaceCompetitionAppealList(raceCompetitionAppeal);
    }

    /**
     * 新增竞赛申诉管理
     * 
     * @param raceCompetitionAppeal 竞赛申诉管理
     * @return 结果
     */
    @Override
    public int insertRaceCompetitionAppeal(RaceCompetitionAppeal raceCompetitionAppeal) {
        raceCompetitionAppeal.setCreateTime(DateUtils.getNowDate());
        raceCompetitionAppeal.setCreateBy(SecurityUtils.getUsername());
        raceCompetitionAppeal.setDelFlag("0");
        raceCompetitionAppeal.setAuditStatus(0); // 默认待审核
        return raceCompetitionAppealMapper.insertRaceCompetitionAppeal(raceCompetitionAppeal);
    }

    /**
     * 修改竞赛申诉管理
     * 
     * @param raceCompetitionAppeal 竞赛申诉管理
     * @return 结果
     */
    @Override
    public int updateRaceCompetitionAppeal(RaceCompetitionAppeal raceCompetitionAppeal) {
        raceCompetitionAppeal.setUpdateTime(DateUtils.getNowDate());
        raceCompetitionAppeal.setUpdateBy(SecurityUtils.getUsername());
        return raceCompetitionAppealMapper.updateRaceCompetitionAppeal(raceCompetitionAppeal);
    }

    /**
     * 批量删除竞赛申诉管理
     * 
     * @param ids 需要删除的竞赛申诉管理主键
     * @return 结果
     */
    @Override
    public int deleteRaceCompetitionAppealByIds(Long[] ids) {
        return raceCompetitionAppealMapper.deleteRaceCompetitionAppealByIds(ids);
    }

    /**
     * 删除竞赛申诉管理信息
     * 
     * @param id 竞赛申诉管理主键
     * @return 结果
     */
    @Override
    public int deleteRaceCompetitionAppealById(Long id) {
        return raceCompetitionAppealMapper.deleteRaceCompetitionAppealById(id);
    }

    /**
     * 审核申诉
     * 
     * @param raceCompetitionAppeal 申诉信息
     * @return 结果
     */
    @Override
    public int auditRaceCompetitionAppeal(RaceCompetitionAppeal raceCompetitionAppeal) {
        raceCompetitionAppeal.setUpdateTime(DateUtils.getNowDate());
        raceCompetitionAppeal.setUpdateBy(SecurityUtils.getUsername());
        raceCompetitionAppeal.setAuditTime(DateUtils.getNowDate());
        raceCompetitionAppeal.setAuditorId(SecurityUtils.getUserId());
        raceCompetitionAppeal.setAuditorName(SecurityUtils.getUsername());
        return raceCompetitionAppealMapper.updateRaceCompetitionAppeal(raceCompetitionAppeal);
    }
}
